﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class Course
    {
        private HashSet<Student> students;

        public Course(HashSet<Student> course)
        {
            this.students = new HashSet<Student>();
            if (course != null)
            {
                foreach (Student st in course)
                {
                    this.students.Add(st);
                }
            }
        }
        public Course()
            : this(null)
        { }

        public int StudentsCount
        {
            get
            {
                return this.students.Count;
            }
        }
        public Student this[int index]
        {
            get
            {
                if (index > -1 && index < this.StudentsCount)
                {
                    return new Student(this.students.ElementAt<Student>(index).Names, 
                                       this.students.ElementAt<Student>(index).FacultyNumber);
                }
                else
                {
                    throw new ArgumentOutOfRangeException("Invalid index");
                }
            }
        }
        
        public bool AddStudent(Student st)
        {
            if (this.students.Contains<Student>(st))
            {
                throw new ArgumentException("Trying to add a student that already has joined the course");
            }
            else
            {
                if (this.students.Count < 30)
                {
                    return this.students.Add(st);
                }
                else
                {
                    return false;
                }
            }
        }
        public bool RemoveStudent(Student st)
        {
            if (!this.students.Contains<Student>(st))
            {
                throw new ArgumentException("Trying to remove a student that is not in the course");
            }
            else
            {
                return this.students.Remove(st);
            }
        }
    }